class Solution {
public:
    long long countInterestingSubarrays(vector<int>& a, int mod, int k) {
        int n = a.size();
        vector<int>s(n + 1);
        for (int i = 1; i <= n; i++) {
            s[i] = s[i - 1];
            if (a[i - 1] % mod == k)s[i]++;
        }
        for (int i = 1; i <= n; i++) {
            cout << s[i] << " ";
        }
        long long ans = 0;
        map<int, int>mp;
        mp[0] = 1;
        for (int i = 1; i <= n; i++) {
            int x = ((s[i] - k) % mod + mod) % mod;
            ans += mp[x];
            mp[(s[i] % mod)]++;
        }
        return ans;
    }
};
// 1 0 1 1
// 1 1 2 3